import * as dotenv from 'dotenv';
import * as path from 'path';

// 根据环境加载对应的配置文件
const env = process.env.NODE_ENV || 'dev';
const envFile = env === 'prd' ? '.env.prd' : '.env.dev';

dotenv.config({ path: path.resolve(process.cwd(), envFile) });
dotenv.config(); // 加载默认.env

export default {
  env: process.env.NODE_ENV || 'dev',
  port: parseInt(process.env.PORT || '3000', 10),
  
  mysql: {
    host: process.env.MYSQL_HOST || 'localhost',
    port: parseInt(process.env.MYSQL_PORT || '3306', 10),
    user: process.env.MYSQL_USER || 'root',
    password: process.env.MYSQL_PASSWORD || '',
    database: process.env.MYSQL_DATABASE || 'member_management',
    connectionLimit: parseInt(process.env.MYSQL_CONNECTION_LIMIT || '10', 10),
  },
  
  redis: {
    host: process.env.REDIS_HOST || 'localhost',
    port: parseInt(process.env.REDIS_PORT || '6379', 10),
    password: process.env.REDIS_PASSWORD || '',
    db: parseInt(process.env.REDIS_DB || '0', 10),
  },
  
  jwt: {
    secret: process.env.JWT_SECRET || 'your-secret-key',
    expiresIn: process.env.JWT_EXPIRES_IN || '7d',
  },
  
  token: {
    expiresIn: parseInt(process.env.TOKEN_EXPIRES_IN || '604800', 10), // 7天，单位秒
  },
  
  rateLimit: {
    max: parseInt(process.env.RATE_LIMIT_MAX || '60', 10),
    window: parseInt(process.env.RATE_LIMIT_WINDOW || '60000', 10), // 60秒
  },
  
  log: {
    level: process.env.LOG_LEVEL || 'info',
  },
};

